import { Sprite } from 'pixi.js';
import BaseSprite from './BaseSprite.js';
import ResourceManager from '../resource.js';

class BackgroundSprite extends BaseSprite {
    constructor(app) {
        super(app, 'background');
        
        this.resources = {
            tree: './tree1.png',
            mountain: './mountain.png'
        };
    }

    async loadResources() {
        for (const [name, url] of Object.entries(this.resources)) {
            await ResourceManager.load(name, url);
        }
    }

    async init() {
        await this.createTree();
        await this.createMountain();
    }

    async createTree() {
        const texture = ResourceManager.get('tree');
        const tree = new Sprite(texture);
        tree.anchor.set(0.5);
        tree.width = 86;
        tree.height = 208;
        tree.x = 100;
        tree.y = 640 - tree.height / 2 - 72;
        this.addSprite(tree);
    }

    async createMountain() {
        const mountainTexture = ResourceManager.get('mountain');
        const mountain = new Sprite(mountainTexture);
        mountain.anchor.set(0.5);
        mountain.width = 150 * 3;
        mountain.height = 58 * 3;
        mountain.x = 600;
        mountain.y = 640 - mountain.height / 2 - 72;
        this.addSprite(mountain);
    }
}

export default BackgroundSprite;
